<template>
    <div class="content">
        <div class="left">
            <div class="print_box">
                <i class="print">校&nbsp;&nbsp;&nbsp;园&nbsp;&nbsp;&nbsp;趣&nbsp;&nbsp;&nbsp;坛</i>
            </div>

            <img src="../assets/login/img2.png" class="people p-animtion" alt="people">
            <img src="../assets/login/img1.png" class="sphere s-animtion" alt="sphere">
        </div>
        <div class="right">
            <div class="top" style="white-space: nowrap;">
                <div class="top-item" @click="GoToHome">
                    <span class="top-text" >前往首页</span>
                </div>
                <div class="top-item">
                    <span class="top-text" @click="Register">注册账号</span>
                </div>
                <div class="top-item">
                    <span class="top-text">关于我们</span>
                </div>
            </div>
                <div class="form-wrappepr" style="overflow: hidden;">
                    <h1 style="white-space: nowrap; display: block;">Enter Our Campus Forum</h1>
                    <input type="text" class="inputs user" placeholder="Enter Student No" v-model="stuId">
                    <input type="password" class="inputs pwd" placeholder="Password" v-model="pwd">
                    <span class="tips" @click="R_pwd">Recovery Password</span>
                    <button class="btn" @click="login" v-loading.fullscreen.lock="loadingFlag">Sigin In</button>
                    <div class="other-login">
                        <div class="divider">
                            <span class="line"></span>
                            <span class="divider-text" style="white-space: nowrap;">湖南工程职业技术学院</span>
                            <span class="line"></span>
                        </div>
                        <!-- <div class="other-login-wrapper">
                            <div class="other-login-item">
                                <img src="" alt="QQ">
                            </div>
                            <div class="other-login-item">
                                <img src="" alt="WeChat">
                            </div>
                        </div> -->
                    </div>
                </div>
        </div>
        <el-dialog
        style="top:-90px !important"
            class="alldialog"
            :visible.sync="dialogVisible"
            :append-to-body="true"
            width="60%"
            :before-close="handleClose">
            <div style="width: 100%; display: flex;align-items: center;justify-content: center;">
                <h1 style="">Enter Our Campus Forum</h1>
            </div>
            <div class="container">
                <div class="form-wrappepr_">
                    <input type="text" class="inputs user" placeholder="Enter Student No" v-model="regiterInfo.stuId">
                    <input type="text" class="inputs pwd" placeholder="Enter nickname" v-model="regiterInfo.nickname">
                    <input type="text" class="inputs pwd" placeholder="Enter email" v-model="regiterInfo.email">
                    <input type="password" class="inputs pwd" placeholder="Enter Password" v-model="regiterInfo.password">
                    <input type="password" class="inputs pwd" placeholder="Reconfirm password" v-model="regiterInfo.r_password">
                    <button class="btn" 
                    style="margin: 10px 0px;"
                    @click="Register_" v-loading.fullscreen.lock="loadingFlag">Confirm registration</button>
                    <div class="other-login">
                        <div class="divider">
                            <span class="line"></span>
                            <span class="divider-text" style="white-space: nowrap;">湖南工程职业技术学院</span>
                            <span class="line"></span>
                        </div>
                      
                    </div>
                </div>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {LOGIN,REGISTER} from "@/api/login"
import {setToken} from "@/utils/auth"
export default {
    name: 'SchoolForumLogin',

    data() {
        return {
            stuId:"202301010101",
            pwd:"123456",
            loginFlag :true,
            loadingFlag:false,
            loading:{},
            dialogVisible:false,
            regiterInfo:{
                stuId:"",
                nickname:"",
                email:"",
                password:"",
                r_password:""
            }
        };
    },

    mounted() {
        document.querySelector(".people").addEventListener('animationend', function () {
        this.classList.remove('p-animtion');
        this.classList.add('p-other-animtion')
        });
        document.querySelector(".sphere").addEventListener('animationend', function () {
            this.classList.remove('s-animtion');
            this.classList.add('s-other-animtion')
        });	
    },

    methods: {
        handleClose(done) {
            this.$confirm('确认取消用户注册吗？取消后当前信息不会保留').then(_ => {
                for (const key in this.regiterInfo) {
                    // 数据清空
                    this.regiterInfo[key] =""
                }
                done();
            })
            .catch(_ => {});
        },
        Register(){
            this.dialogVisible = true
        },
        R_pwd(){
            // 忘记密码
            this.$alert("忘记账户请联系班级辅导员，进行密码找回!")
        },
        GoToHome(){
            
            this.$router.replace("/index")
            
        },
        // 进行账户注册
        Register_(){
            // 非空校验
            for (const key in this.regiterInfo) {
                if(this.regiterInfo[key].trim() == ""){
                    this.$message.error("请完善注册信息")
                    return
                }
            }
            // 学号校验
            if(this.regiterInfo["stuId"].trim().length!=12){
                this.$message.error("请输入正确的学号")
                return
            }
            // 邮箱校验
            var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
            if( !reg.test(this.regiterInfo["email"])){
                this.$message.error("请输入正确的邮箱号")
                return
            }
            // 密码格式校验
            if(this.regiterInfo["password"].trim().length<6 || this.regiterInfo["password"].trim().length>13 ){
                this.$message.error("密码格式不正确!最小长度为不得小于6,最大长度不得大于13!")
                return
            }

            // 重复密码校验
            if(this.regiterInfo["r_password"].trim() != this.regiterInfo["password"].trim()){
                this.$message.error("两次输入的密码不一致!")
                return
            }
            
            // 完成数据校验 进行用户注册
            REGISTER(this.regiterInfo).then(res=>{
                this.$message.success("注册成功!")
                // 数据清空
                for (const key in this.regiterInfo) {
                    this.regiterInfo[key] =""
                }
                this.dialogVisible = false
            }).catch(error=>{
                this.$message.error("注册失败！")
            })
        },
        login(){
            if(this.stuId!='',this.pwd!=''){
                this.loadingFlag= true
                LOGIN(this.stuId,this.pwd).then(res=>{
                    console.log(res);
                    setTimeout(()=>{

                        this.$message.success("登录成功!")

                        // 设置Token
                        this.$store.dispatch('user/login', res.token)

                        // console.log(this.$store.state.user.token);
                        // 设置UserInfo
                        this.$store.dispatch("user/setUser",res.userInfo)

                    
                        console.log(this.$store.state.user.user);

                        this.loadingFlag = false

                        this.$router.replace("/index")
                    },1000)

                }).catch(err=>{
                    this.loadingFlag = false
                })
            }else{
                this.$message.error("请完善登录信息!")
            }
        }
    },
};
</script>

<style lang="scss" scoped>
:root {
    font-size: 15px;
}
body {
    margin: 0;
    min-height: 100vh;
    background-color: #abc6f8;
    background-image: radial-gradient(closest-side, rgb(255, 255, 255), rgba(235, 105, 78, 0)),
        radial-gradient(closest-side, rgb(250, 203, 203), rgba(243, 11, 164, 0)),
        radial-gradient(closest-side, rgb(237, 252, 202), rgba(254, 234, 131, 0)),
        radial-gradient(closest-side, rgb(197, 248, 241), rgba(170, 142, 245, 0)),
        radial-gradient(closest-side, rgb(206, 200, 243), rgba(248, 192, 147, 0));
    background-size: 130vmax 130vmax, 80vmax 80vmax, 90vmax 90vmax, 110vmax 110vmax, 90vmax 90vmax;
    background-position: -80vmax -80vmax, 60vmax -30vmax, 10vmax 10vmax, -30vmax -10vmax, 50vmax 50vmax;
    background-repeat: no-repeat;
    animation: 10s movement linear infinite;
}
body::after {
    content: "";
    display: block;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.content {  
    width: 90vw;
    height: 90vh;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.18);
    display: flex;
    // overflow: hidden;
    .btn:hover{
        box-shadow: 1px 1px 15px 0 rgba(117, 12, 8, 0.37) !important;
    }
    .left {
        flex: 1;
        position: relative;
        .sphere {
            position: absolute;
            left: 30%;
            width: 90%;
            z-index: 1;
            animation: sphereAnimation 2s;
            animation-fill-mode: forwards;
            animation-timing-function: ease;
        }
        .people {
            position: absolute;
            left: -50%;
            top: 20%;
            width: 70%;
            // height: 100px;
            z-index: 2;
        }
        .p-animtion {
            animation: peopleAnimation 2s;
            animation-fill-mode: forwards;
            animation-timing-function: ease;
        }
        .p-other-animtion {
            animation-name: pOtherAnimation; // 动画名称
            animation-direction: alternate; // 动画在奇数次（1、3、5...）正向播放，在偶数次（2、4、6...）反向播放。
            animation-timing-function: linear; // 动画执行方式，linear：匀速；ease：先慢再快后慢；ease-in：由慢速开始；ease-out：由慢速结束；ease-in-out：由慢速开始和结束；
            animation-iteration-count: infinite; //  动画播放次数，infinite：一直播放
            animation-duration: 3s; // 动画完成时间
        }
        .s-animtion {
            animation: sphereAnimation 2s;
            animation-fill-mode: forwards;
            animation-timing-function: ease;
        }
        .s-other-animtion {
            animation-name: sOtherAnimation; // 动画名称
            animation-direction: alternate; // 动画在奇数次（1、3、5...）正向播放，在偶数次（2、4、6...）反向播放。
            animation-timing-function: linear; // 动画执行方式，linear：匀速；ease：先慢再快后慢；ease-in：由慢速开始；ease-out：由慢速结束；ease-in-out：由慢速开始和结束；
            animation-iteration-count: infinite; //  动画播放次数，infinite：一直播放
            animation-duration: 3s; // 动画完成时间
        }
    }
    .right {
        flex: 1;
        position: relative;
        z-index: 12;
        .top {
            width: 80%;
            margin-left: 38px;
            color: rgb(51, 52, 124);
            font-size: 20px;
            font-weight: 600;
            font-family: "Century Gothic", Times, serif;
            position: absolute;
            left: 50%;
            top: 5%;
            transform: translate(-50%, 0);
            .top-item {
                float: left;
                width: 150px;
                height: 40px;
                line-height: 40px;
                text-align: center;
                margin-right: 10px;
                transition: 0.5s;
                font-family:Arial, Helvetica, sans-serif;

                &:hover {
                    border: 0;
                    background-color: #fff;
                    border-radius: 50px;
                    cursor: pointer;
                    box-shadow: -20px 10px 32px 1px rgba(182, 183, 185, 0.37);
                }
            }
        }
        .form-wrappepr {
            width: 60%;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            text-align: right;
            h1 {
                float: left;
                font-family: "Century Gothic", Times, serif;
                margin: 30px 0;
                // color: rgb(68,96,241);
            }
            .inputs {
                display: block;
                width: 100%;
                height: 70px;
                margin: 30px 0;
                border-radius: 10px;
                border: 0;
                background-color: rgb(210 223 237);
                color: rgb(80, 82, 84);
                font-family: "Century Gothic", Times, serif;
                outline: none;
                padding: 20px;
                box-sizing: border-box;
                font-size: 20px;
            }
            .tips {
                display: block;
                margin-top: -15px;
                color: rgb(160, 170, 182);
                cursor: pointer;
            }
            button {
                width: 100%;
                height: 50px;
                background-color: rgb(68, 96, 241);
                border-radius: 10px;
                font-size: 15px;
                color: #fff;
                border: 0;
                font-weight: 600;
                margin: 30px 0;
                cursor: pointer;
                box-shadow: 1px 1px 15px 0 rgba(62, 145, 255, 0.37);
                font-family: "Century Gothic", Times, serif;
            }
            .other-login {
                .divider {
                    width: 100%;
                    margin: 20px 0;
                    text-align: center;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    .line {
                        display: inline-block;
                        max-width: 35%;
                        width: 35%;
                        flex: 1;
                        height: 1px;
                        background-color: rgb(162, 172, 185);
                    }
                    .divider-text {
                        vertical-align: middle;
                        margin: 0px 20px;
                        // line-height: 0px;
                        display: inline-block;
                        width: 150px;
                        color: rgb(162, 172, 185);
                        white-space: normal;
                    }
                }
                .other-login-wrapper {
                    width: 100%;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    .other-login-item {
                        width: 70px;
                        // border: 1px solid rgb(162, 172, 185);
                        padding: 10px;
                        text-align: center;
                        border-radius: 10px;
                        cursor: pointer;
                        font-weight: 600;
                        color: rgb(51, 49, 116);
                        margin: 0 10px;
                        transition: 0.4s;
                        img {
                            width: 40px;
                            height: 40px;
                            vertical-align: middle;
                        }
                        span {
                            vertical-align: middle;
                        }

                        &:hover {
                            width: 80px;
                            height: 50%;
                            background-color: #fff;
                            border: 0;
                            box-shadow: -20px 10px 32px 1px rgba(182, 183, 185, 0.37);
                        }
                    }
                }
            }
        }
    }
}
@keyframes movement {
    0%,
    100% {
        background-size: 130vmax 130vmax, 80vmax 80vmax, 90vmax 90vmax, 110vmax 110vmax, 90vmax 90vmax;
        background-position: -80vmax -80vmax, 60vmax -30vmax, 10vmax 10vmax, -30vmax -10vmax, 50vmax 50vmax;
    }
    25% {
        background-size: 100vmax 100vmax, 90vmax 90vmax, 100vmax 100vmax, 90vmax 90vmax, 60vmax 60vmax;
        background-position: -60vmax -90vmax, 50vmax -40vmax, 0vmax -20vmax, -40vmax -20vmax, 40vmax 60vmax;
    }
    50% {
        background-size: 80vmax 80vmax, 110vmax 110vmax, 80vmax 80vmax, 60vmax 60vmax, 80vmax 80vmax;
        background-position: -50vmax -70vmax, 40vmax -30vmax, 10vmax 0vmax, 20vmax 10vmax, 30vmax 70vmax;
    }
    75% {
        background-size: 90vmax 90vmax, 90vmax 90vmax, 100vmax 100vmax, 90vmax 90vmax, 70vmax 70vmax;
        background-position: -50vmax -40vmax, 50vmax -30vmax, 20vmax 0vmax, -10vmax 10vmax, 40vmax 60vmax;
    }
}
@keyframes sphereAnimation {
    0% {
        width: 10%;
    }
    100% {
        width: 90%;
        transform: translate(-30%, 5%);
    }
}
@keyframes peopleAnimation {
    0% {
        width: 40%;
    }
    100% {
        width: 70%;
        transform: translate(90%, -10%);
    }
}
@keyframes pOtherAnimation {
    0% {
        transform: translate(90%, -10%);
    }
    100% {
        transform: translate(90%, -15%);
    }
}
@keyframes sOtherAnimation {
    0% {
        transform: translate(-30%, 5%);
    }
    100% {
        transform: translate(-30%, 10%);
    }
}
.container{
    display: flex;
    justify-content: center;
    align-items: center;
    // height: 430px;
    height: 100%;
    overflow: auto;
}
.form-wrappepr_ {
    overflow: auto;
    width: 60%;
    // margin-top: 200px;
    //    transform: translate(-50%, -50%);
    text-align: right;
    h1 {
        float: left;
        font-family: "Century Gothic", Times, serif;
        margin: 30px 0;
        // color: rgb(68,96,241);
    }
    .inputs {
        display: block;
        width: 100%;
        height: 55px;
        margin: 30px 0;
        border-radius: 10px;
        border: 0;
        background-color: rgb(210 223 237);
        color: rgb(80, 82, 84);
        font-family: "Century Gothic", Times, serif;
        outline: none;
        padding: 20px;
        box-sizing: border-box;
        font-size: 20px;
    }
    .tips {
        display: block;
        margin-top: -15px;
        color: rgb(160, 170, 182);
        cursor: pointer;
    }
    button {
        width: 100%;
        height: 50px;
        background-color: rgb(68, 96, 241);
        border-radius: 10px;
        font-size: 15px;
        color: #fff;
        border: 0;
        font-weight: 600;
        margin: 30px 0;
        cursor: pointer;
        box-shadow: 1px 1px 15px 0 rgba(62, 145, 255, 0.37);
        font-family: "Century Gothic", Times, serif;
    }
    .other-login {
        .divider {
            width: 100%;
            margin: 20px 0;
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .line {
                display: inline-block;
                max-width: 35%;
                width: 35%;
                flex: 1;
                height: 1px;
                background-color: rgb(162, 172, 185);
            }
            .divider-text {
                vertical-align: middle;
                margin: 0px 20px;
                // line-height: 0px;
                display: inline-block;
                width: 150px;
                color: rgb(162, 172, 185);
                white-space: normal;
            }
        }
        .other-login-wrapper {
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            .other-login-item {
                width: 70px;
                // border: 1px solid rgb(162, 172, 185);
                padding: 10px;
                text-align: center;
                border-radius: 10px;
                cursor: pointer;
                font-weight: 600;
                color: rgb(51, 49, 116);
                margin: 0 10px;
                transition: 0.4s;
                border-radius:10px
                img {
                    width: 40px;
                    height: 40px;
                    vertical-align: middle;
                }
                span {
                    vertical-align: middle;
                }

                &:hover {
                    width: 80px;
                    height: 50%;
                    background-color: #fff;
                    border: 0;
                    box-shadow: -20px 10px 32px 1px rgba(182, 183, 185, 0.37);
                }
            }
        }
    }
    .btn:hover{
        box-shadow:  1px 1px 15px 0 rgba(117, 12, 8, 0.37) !important;
    }
}   
.print_box {
  // border: 1px solid red;
  height: 180px;
  margin: 0 0 20px 0;
  background-color: #ffffff;
  // background: url("https://w.wallhaven.cc/full/x6/wallhaven-x66olo.jpg") no-repeat;
  margin-top: 15%;
  left: 30%;
  position: absolute;
  z-index: 999;
  .print {
    // width: 100px;
    color: #113f65;
    font-size: 50px;
    font-weight: bolder;
    position: absolute;
    // top: 60%;
    left: 40%;
    margin-top: -60px;
    margin-left: -60px;
    // border: 1px solid red;
  }
}
@media screen and (max-width: 1250px){
    .top-item:nth-child(3){display: none;}
}

</style>